﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace bxml.betterxml.xir
{
    public class XIRReader
    {
        private TextReader lineOrientedReader;
        private bool inputDone;

        public XIRReader(TextReader input)
        {
            lineOrientedReader = input;
        }

        public XIRDataObject getNextRecord()
        {
            List<String> record = new List<String>(50);
            String inLine;

            while (!inputDone)
            {
                try
                {
                    inLine = lineOrientedReader.ReadLine();
                    if (string.IsNullOrEmpty(inLine))
                        break;
                }
                catch (IOException)
                {
                    inputDone = true;
                    break;
                }
                record.Add(inLine);
            }

            XIRDataObject xir = XIRDataObject.getXIRDataObject(record);
            return xir;
        }
    }
}
